import { Tag } from "antd"
import { ColumnGroupType, ColumnType } from "antd/es/table"
import dayjs from "dayjs"

import { timeTurner } from "@/utils"
import { handleNumber } from "@/utils/util"

const RebateCheckRecordColumns = (
	newFormat: (arg: string) => string
	// renderCopyNo: (arg: string) => any
): Record<string, ColumnGroupType<any> | ColumnType<any>> => {
	const orderStatusMap: { [key: number]: string } = {
		1: newFormat("funds.fund_audit.audit_fail_1"),
		3: newFormat("funds.fund_audit.audit_fail_2"),
		4: newFormat("funds.fund_audit.pass_the_audit")
	}

	const getRebateCycle = (date1: any, date2: any) => {
		date1 = date1 && dayjs(String(date1)).format("YYYY-MM-DD")
		date2 = date2 && dayjs(String(date2)).format("YYYY-MM-DD")

		if (date1 === date2) {
			return date1 || "-"
		} else {
			return date1 && date2 ? date1 + " - " + date2 : "-"
		}
	}

	return {
		rebateCheckRecord_cycleName: {
			title: newFormat("funds.fund_audit.rebates_cycle"),
			dataIndex: "cycleName",
			key: "cycleName",
			width: 180,
			align: "center",
			render: (text: string, record: any) => getRebateCycle(record.cycleStatrtDate, record.cycleEndDate)
		},
		rebateCheckRecord_proxyName: {
			title: newFormat("funds.proxy_name"),
			dataIndex: "proxyName",
			key: "proxyName",
			align: "center",
			width: 130,
			render: (text: string) => text || "-"
		},
		rebateCheckRecord_rebateAmount: {
			title: `${newFormat("funds.proxy_member_funds_record.person_rebate_amount")}`,
			dataIndex: "rebateAmount",
			key: "rebateAmount",
			align: "center",
			width: 180,
			render: (_text: string, record: any) => <span>{handleNumber(record.currency, record.personRebateAmount)}</span>
		},
		rebateCheckRecord_orderStatus: {
			title: newFormat("funds.fund_audit.order_status"),
			dataIndex: "orderStatus",
			key: "orderStatus",
			align: "center",
			width: 140,
			render: (text: number) => <Tag color={text === 4 ? "green" : "red"}>{orderStatusMap[text] || "-"}</Tag>
		},
		rebateCheckRecord_auditTime: {
			title: newFormat("funds.fund_audit.audit_time"),
			dataIndex: "auditTime",
			key: "auditTime",
			width: 220,
			align: "center",
			render: (text: string, record: any) => (
				<div>
					<p>
						{newFormat("funds.fund_audit.audit_text_1")}: {record.audit1Time || "-"}
					</p>
					{record.audit1Result === 1 && (
						<p>
							{newFormat("funds.fund_audit.audit_text_2")}: {record.audit2Time || "-"}
						</p>
					)}
				</div>
			)
		},
		rebateCheckRecord_auditCost: {
			title: newFormat("funds.fund_audit.audit_cost"),
			dataIndex: "auditCost",
			key: "auditCost",
			width: 150,
			align: "center",
			render: (text: string, record: any) => (
				<div>
					<p>
						{newFormat("funds.fund_audit.audit_text_1")}: {timeTurner(record.audit1Cost) || "-"}
					</p>
					{record.audit1Result === 1 && (
						<p>
							{newFormat("funds.fund_audit.audit_text_2")}: {timeTurner(record.audit2Cost) || "-"}
						</p>
					)}
				</div>
			)
		},
		rebateCheckRecord_lockAccount: {
			title: newFormat("funds.fund_audit.lock_account"),
			dataIndex: "lockAccount",
			key: "lockAccount",
			width: 220,
			align: "center",
			render: (text: string, record: any) => (
				<div>
					<p>
						{newFormat("funds.fund_audit.audit_text_1")}: {record.audit1Operator || "-"}
					</p>
					{record.audit1Result === 1 && (
						<p>
							{newFormat("funds.fund_audit.audit_text_2")}: {record.audit2Operator || "-"}
						</p>
					)}
				</div>
			)
		}
	}
}

export default RebateCheckRecordColumns
